package com.wll.ec.core.ui.banner;

import android.content.Context;
import android.view.View;

import androidx.appcompat.widget.AppCompatImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

/**
 * created by detachment on 2020/3/21
 */

public class ImageHolder implements Holder<String> {

    private AppCompatImageView mImageView = null;
    private static final RequestOptions BANNER_OPTIONS = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .dontAnimate()
            .centerCrop();

    @Override
    public View createView(Context context) {
        mImageView = new AppCompatImageView(context);
        return mImageView;
    }

    @Override
    public void UpdateUI(Context context, int position, String data) {
        Glide.with(context)
//                .asBitmap()
                .load(data)
                .apply(BANNER_OPTIONS)
                .into(mImageView);
//                .into(new SimpleTarget<Bitmap>() {
//                    @Override
//                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
//                        int width = resource.getWidth();//图片原始宽度
//                        int height = resource.getHeight();//图片原始高度
//                        int scaledH = DimenUtil.dip2px(260f);//固定图片展示高度为180dp
//                        int scaledW = (width * scaledH) / height;//计算出按比缩放后的宽度
//                        ViewPager.LayoutParams lp = new ViewPager.LayoutParams();
//                        lp.width = scaledW;
//                        lp.height = scaledH;
//                        mImageView.setLayoutParams(lp);
//                        mImageView.setImageBitmap(resource);
////                                Glide.with(Ec.getApplicationContext())
////                                        .load(url)
////                                        .apply(OPTIONS)
////                                        .into(imageView);
//                    }
//                });
    }
}
